﻿@model PhoneBilling.Models.GroupPaymentDetailModel
<script type="text/javascript">
    function print() {
        if (checkedCustomer.length == 0) {
            alert("请选择");
            return;
        }
        var url = "\PaymentPrint?groupID=@Model.ID";
        var str = checkedCustomer.join('-');

        url = url + "&monthTxt=" + str;
        window.open(url, "_blank");
    }
    function beforeSubmit() {
        if (checkedCustomer.length == 0) {
            alert("请选择");
            return;
        }
        var str = checkedCustomer.join('-');
        $(".Month").val(str);
    }
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnConfirm").ligerButton(
        {
            click: function () {
                beforeSubmit();
                $('form').submit();
            }
        });
        $("#btnPrint").ligerButton(
        {
            click: function () {
                print();
            }
        });
    });
    
</script>
<h3 class="title">
    <label>
        部门：</label><label class="listCounts">@Model.部门</label>
    <label>
        分组：</label><label class="listCounts">@Model.分组</label>
</h3>
@using (Html.BeginForm("GroupPaymentDetail", "Billing"))
{
    @Html.HiddenFor(m => m.ID)
    @Html.HiddenFor(m => m.MonthTxt, new { @class = "Month" })
    <div>
        @*<p>
        <label>总金额：</label><label class="listCounts">@Model.总金额</label>
        </p>*@ @* @{
             var grid = new WebGrid(source: Model.AccountList, canPage: false);
        }
        @grid.GetHtml(
            alternatingRowStyle: "bg",
            columns: grid.Columns
            (
                  grid.Column(format: (item) => Html.CheckBox("选择", true, new { id = item.月份Txt, @class = "account" })),
                  grid.Column("月份", "月份"),
                  grid.Column("月租费", "月租费"),
                  grid.Column("功能费", "功能费"),
                  grid.Column("通话费", "通话费"),
                  grid.Column("总次数", "总次数"),
                  grid.Column("总金额", "总金额"),
                  grid.Column(format: (item) => Html.ActionLink("打印", "PaymentPrint", new { groupID = Model.ID, monthTxt =  item.Year +"-"+item.Month}, new { target = "_blank" }))
            )
        )*@
        <div class="system_input_contain">
            <input type="button" id="btnConfirm" value="确定" />
            <input type="button" id="btnPrint" value="打印" />
        </div>
        <div id="maingrid">
        </div>
    </div>
}
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.AppendLine(string.Format("var data={{Total:{0},", Model.AccountList.Count));
    sb.AppendLine("Rows:[");
    for (int i = 0; i < Model.AccountList.Count; i++)
    {
        var item = Model.AccountList[i];
        if (i == 0)
        {
            sb.Append("{");
        }
        else
        {
            sb.Append(",{");
        }
        sb.Append(string.Format("月份:'{0}',", item.月份));
        sb.Append(string.Format("月份Txt:'{0}',", item.月份Txt));
        sb.Append(string.Format("月租费:'{0}',", item.月租费));
        sb.Append(string.Format("功能费:'{0}',", item.功能费));
        sb.Append(string.Format("通话费:'{0}',", item.通话费));
        sb.Append(string.Format("总次数:'{0}',", item.总次数));
        sb.Append(string.Format("月租费:'{0}',", item.月租费));
        sb.Append(string.Format("总金额:'{0}'", item.总金额));
        sb.Append("}");
    }
    sb.AppendLine("]};");
    string data = sb.ToString();
}
<script type="text/javascript">
    @Html.Raw(data)
    
    var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '打印', click: printclick },
            ]
        });
    var grid;
    $(function () {

        grid = $("#maingrid").ligerGrid({
            columns: [
                { display: '月份', name: '月份',width:80},
                { display: '月租费', name: '月租费',width:80},
                { display: '功能费', name: '功能费',width:80},
                { display: '通话费', name: '通话费',width:80},
                { display: '总次数', name: '总次数',width:140,totalSummary:                    {render: function (suminf, column, cell){                            return '<div>总次数:' + suminf.max + '</div>';                        }}},
                { display: '总金额', name: '总金额',width:140,totalSummary:                    {render: function (suminf, column, cell){                            return '<div>总金额:' + suminf.max + '</div>';                        }}}],
                isScroll: false, data: data,pageSize:30,alternatingRow:true,  checkbox: true, isChecked: f_isChecked,onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow,
                onContextmenu: function (node, e) {
            actionNodeID = node;
            menu.show({ top: e.pageY, left: e.pageX });
            return false;
        }
        }
        );resetGridHeight(grid);
        $(window).resize(function () {
                resetGridHeight(grid);
            });
    });    function f_isChecked(rowdata)    {            return false;    }    function f_onCheckAllRow(checked)    {        for (var rowid in this.records)        {            if(checked)                addCheckedCustomer(this.records[rowid]['月份Txt']);            else                removeCheckedCustomer(this.records[rowid]['月份Txt']);        }    }    var checkedCustomer = [];    function findCheckedCustomer(CustomerID)    {
        for(var i =0;i<checkedCustomer.length;i++)        {            if(checkedCustomer[i] == CustomerID) return i;        }        return -1;    }        function addCheckedCustomer(CustomerID)    {        if(findCheckedCustomer(CustomerID) == -1)            checkedCustomer.push(CustomerID);    }
    function removeCheckedCustomer(CustomerID)    {        var i = findCheckedCustomer(CustomerID);        if(i==-1) return;        checkedCustomer.splice(i,1);    }    function f_onCheckRow(checked, data)    {        if (checked){  addCheckedCustomer(data.月份Txt);  }        else {removeCheckedCustomer(data.月份Txt); }    }    function printclick(item, i) {
        var row = grid.getSelectedRow();
        if(row != null)
        {
            var url = "\PaymentPrint?groupID=@Model.ID";
            url = url + "&monthTxt=" + row.月份Txt;
            window.open(url, "_blank");;
        }
    }</script>
